﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Input;
using System.Diagnostics;
using System.Collections.ObjectModel;
using System.Collections;

namespace AliyunMobileTestTechnology.ViewModel.Commands
{
    class StartCollectCovCommand : ICommand
    {
        private WorkPlatformViewModel workPlatformViewModel;
        public StartCollectCovCommand(WorkPlatformViewModel workPlatformViewModel)
        {
            this.workPlatformViewModel = workPlatformViewModel;
        }

        public bool CanExecute(object parameter)
        {

            return true;
        }

        public event EventHandler CanExecuteChanged;

        public void Execute(object parameter)
        {

            IList modules = parameter as IList;
           
            List<string> cmdList = new List<string>();
            if (modules.Count != 0)
            {
                Module module = (Module)modules[0];
                if (module.Name == "All")
                {
                    cmdList.Add("adb shell am broadcast -a aliyun.intent.action.resetcoverage");
                }
                else
                {
                    foreach (string packagename in module.Packages)
                    {
                        cmdList.Add(string.Format("adb shell am broadcast -e packagename {0} -a aliyun.intent.action.resetcoveragebyname", packagename));
                    }
                }
            }

            foreach (string cmd in cmdList)
            {
                string output = WorkPlatformViewModel.ExecuteCommand(cmd);
            }


            workPlatformViewModel.ListViewIsEnable = false;
        }


    }
}
